<template>
	<view class="content">
		<image src="../../static/login/zhanghaotip.png" class="zhanghaotishi"></image>
		<view class="name-box">
			<input type="text" v-model.trim="name" class="name-input" />
		</view>
		<view class="wwid-box">
			<input type="text" v-model.trim="wwid" class="name-input" />
		</view>
		<view class="login-btn" @click="loginBtn">

		</view>
		<view class="chakanguize" @click="seeGuiZe">

		</view>
		
		<!-- 弹窗规则 -->
		<view class="mark-box animated" :class="tipShow?'fadeIn':'fadeOut'" v-if="tipShow">
			<image src="../../static/login/tip.png" class="tips"></image>
			<view class="close-btn" @click="closeGuiZe">
				
			</view>
		</view>
		
		<!-- 登录后界面 -->
		<view class="choose-zhenying-box" v-if="dengluhou">
			<image :src="'../../static/fenxiang/'+index+'.png'" v-for="(i,index) in zhenying_txt" v-if="tuijianzhenying==i.zhenying" class="zhenying-txt"></image>
			<view class="join-btn" @click="jionZhenying"></view>
			<view class="see-btn" @click="seeRicheng"></view>
			<view class="choose-btn" @click="zixuan"></view>
		</view>
		
		<!-- 日程弹窗 -->
		<view class="mark-box animated" :class="tanchuangShow?'fadeIn':'fadeOut'" v-if="tanchuangShow">
			<image :src="i"  v-for="(i,index) in tanchuangList" v-if="index==current" class="tanchuang-size"></image>
			<view class="close-btn" @click="closeRicheng">
				
			</view>
		</view>
		
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dengluhou:false,
				tanchuangShow:false,
				name: '',
				wwid: '',
				tipShow:false,
				tuijianzhenying:'',
				tuijianname:'',
				tuijianwwid:'',
				tuijianid:'',
				current:'',
				zhenying_txt:[
					{
						zhenying:'创新',
						img:require('../../static/fenxiang/0.png')
					},
					{
						zhenying:'团队',
						img:require('../../static/fenxiang/1.png')
					},
					{
						zhenying:'专业',
						img:require('../../static/fenxiang/2.png')
					},
					{
						zhenying:'准入',
						img:require('../../static/fenxiang/3.png')
					},
				],
				tanchuangList:[require('../../static/zhenying/0/tanchuang.png'),require('../../static/zhenying/1/tanchuang.png'),require('../../static/zhenying/2/tanchuang.png'),require('../../static/zhenying/3/tanchuang.png')]
			}
		},
		onLoad() {
			
		},
		onShow() {
			var uri = window.location.href.split('?')[1];
			console.log(uri)
			if (uri) {
				let list = uri.split('&')
				this.tuijianid = decodeURIComponent(list[0]).split('=')[1]
				// this.tuijianwwid = decodeURIComponent(list[1]).split('=')[1]
				this.current = decodeURIComponent(list[1]).split('=')[1]
				this.tuijianzhenying = decodeURIComponent(list[2]).split('=')[1]
				
				console.log('推荐ID：',this.tuijianid)
				// console.log('推荐wwid：',this.tuijianwwid)
				console.log('推荐阵营：',this.tuijianzhenying)
				console.log('推荐current：',this.current)
			} else{
				uni.redirectTo({
					url:'../index/index'
				})
			}
		},
		methods: {
			seeGuiZe() {
				this.tipShow=true
			},
			closeGuiZe(){
				this.tipShow=false
			},
			seeRicheng(){
				this.tanchuangShow = true
			},
			closeRicheng(){
				this.tanchuangShow = false
			},
			loginBtn() {
				uni.showLoading({
					title:'loading',
					mask:true
				})
				console.log('name',this.name)
				console.log('wwid',this.wwid)
				if (this.name && this.wwid) {
					/* 云验证账号 */
					uniCloud.callFunction({
						name:'login',
						data:{name:this.name,wwid:this.wwid},
						success: (res) => {
							console.log(res)
							if (res.result.data.length>0) {
								uni.setStorageSync('name',res.result.data[0].name)
								uni.setStorageSync('wwid',res.result.data[0].wwid)
								uni.setStorageSync('userID',res.result.data[0]._id)
								if (this.tuijianid==res.result.data[0]._id) {
									uni.hideLoading()
									uni.showModal({
										content:'不能使用自己的分享',
										showCancel:false,
										success: (res) => {
											if(res.confirm){
												uni.redirectTo({
													url:'../index/index'
												})
											}
										}
									})
								}else{
									uni.hideLoading()
									
									this.dengluhou = true
								}
								
							} else{
								uni.hideLoading()
								uni.showToast({
									title:'姓名和WWID错误',
									icon:'error'
								})
								
							}
							
						}
					})
					
				} else{
					uni.hideLoading()
					uni.showToast({
						title:'请输入姓名和WWID',
						icon:'none'
					})
				}
				
				
			},
			jionZhenying(){
				uni.showLoading({
					title:'loading',
					mask:true
				})
				uniCloud.callFunction({
					name:'zhibo',
					success: (res) => {
						console.log(res)
						if (res.result.data[0].zhibo==0) {
							uni.hideLoading()
							uni.showModal({
								content:'直播还未开始',
								showCancel:false
							})
						} else{
							uni.hideLoading()
							/* 去选座页面 */
							uni.redirectTo({
								url:'../xuanzuo/xuanzuo?tuijianid='+this.tuijianid+'&current='+this.current
							})
						}
					}
				})
			},
			zixuan(){
				uni.redirectTo({
					url:'../zixuanzhenying/zixuanzhenying'
					
				})
			}
		}
	}
</script>

<style scoped>
	page {
		background: url(../../static/login/bg1.jpg) no-repeat center top;
		background-size: 100% auto;
	}


	.zhanghaotishi {
		width: 216rpx;
		height: 40rpx;
		margin-top: 586rpx;
	}

	.name-box {
		width: 484rpx;
		height: 82rpx;
		background: url(../../static/login/name.png) no-repeat center center;
		background-size: 100% 100%;
		margin-top: 66rpx;
		position: relative;
	}

	.wwid-box {
		width: 484rpx;
		height: 82rpx;
		background: url(../../static/login/wwid.png) no-repeat center center;
		background-size: 100% 100%;
		margin-top: 30rpx;
		position: relative;
	}

	.login-btn {
		width: 526rpx;
		height: 126rpx;
		background: url(../../static/login/login.png) no-repeat center center;
		background-size: 100% 100%;
		margin-top: 20rpx;
	}

	.chakanguize {
		width: 292rpx;
		height: 34rpx;
		background: url(../../static/login/huodongguize.png) no-repeat center center;
		background-size: 100% 100%;
		margin-top: 56rpx;
	}
	.name-input{
		width: 316rpx;
		height: 56rpx;
		position: absolute;
		top: 50%;
		left: 140rpx;
		transform: translateY(-50%);
		color: #fff;
		font-size: 28rpx;
	}
	.mark-box{
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		background: rgba(0,0,0,0.5);
		display: flex;
		flex-direction: column;
		align-items: center;
		z-index: 100;
	}
	.tips{
		width: 566rpx;
		height: 784rpx;
		margin-top: 166rpx;
	}
	.close-btn{
		width: 70rpx;
		height: 72rpx;
		background: url(../../static/login/close.png) no-repeat center center;
		background-size: 100% 100%;
		margin-top: 50rpx;
	}
	.choose-zhenying-box{
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		background: url(../../static/fenxiang/bg4.jpg) no-repeat center top;
		background-size: 100% auto;
		display: flex;
		flex-direction: column;
		align-items: center;
		z-index: 90;
	}
	
	.zhenying-txt{
		width: 386rpx;
		height: 170rpx;
		margin-top: 566rpx;
	}
	
	.join-btn{
		width: 464rpx;
		height: 126rpx;
		background: url(../../static/fenxiang/jiaru.png) no-repeat center center;
		background-size: 100% 100%;
		margin-top: 34rpx;
	}
	.see-btn,.choose-btn{
		width: 464rpx;
		height: 126rpx;
	}
	.see-btn{
		background: url(../../static/fenxiang/chakan.png) no-repeat center center;
		background-size: 100% 100%;
	}
	.choose-btn{
		background: url(../../static/fenxiang/xuanze.png) no-repeat center center;
		background-size: 100% 100%;
	}
	.tanchuang-size{
		width: 606rpx;
		height: 864rpx;
		margin-top: 166rpx;
	}
</style>
